import region from '@/assets/region.json';

export const AreaMap = new Map();

export const getAddrByCode = (p: string, c: string, d: string) => {
  const path = `${p}-${c}-${d}`;

  if (AreaMap.has(path)) {
    return AreaMap.get(path);
  }

  const pValue = region.find((e) => {
    return e.value === p;
  });

  const cValue = pValue?.children.find((e) => {
    return e.value === c;
  });

  const dValue = cValue?.children?.find((e) => {
    return e.value === d;
  });

  const result = [pValue?.label, cValue?.label, dValue?.label].join('-');

  AreaMap.set(path, result);

  return result;
};
